/**
 * 档案借阅----已审核
 */
import React from "react";
import PropTypes from "prop-types";
import { routerRedux } from "dva/router";
import { connect } from "dva";
import { Row, Col, Button, Table, Badge } from "antd";
import { filterState, filterMediumType, filterBorrowState } from "utils/filter";
import { formatDate } from "utils";

const MyApplication = ({ location, dispatch, loading, borrow }) => {
  const { list, pagination } = borrow;
  const getWorkHistory = payload => {
    dispatch({
      type:"borrow/getworkflowHistory",
      payload:{processInstanceId:payload.processInstanceId}
    })
  }
  const getSliderDetails = record =>{
    getWorkHistory(record)
    dispatch({
      type:"borrow/getSliderDetails",
      payload:{record}
    })
    $("#sliderDetails").animate({ right: "0" });
  };
  const columns = [
    {
      title: "档案年度",
      key: "documentYear",
      dataIndex: "documentYear"
    },
    {
      title: "公证事项",
      key: "notarialMatters",
      dataIndex: "notarialMatters",
      render: (text, record) => {
        const datas = text.split("#")
        const ary = []
        datas.map((item, i) => {
          ary.push(
            <p>{item}</p>
          )
        })
        return ary
      }
    },
    {
      title: "申请人",
      key: "applyName",
      dataIndex: "applyName",
      render: (text, record) => {
        const datas = text.split("#")
        const ary = []
        datas.map((item, i) => {
          ary.push(
            <p>{item}</p>
          )
        })
        return ary
      }
    },
    {
      title: "借阅方式",
      key: "borrowMediumType",
      dataIndex: "borrowMediumType",
      render: (record, text) => filterMediumType(record)
    },
    {
      title: "申请提交日期",
      key: "borrowApplyTime",
      dataIndex: "borrowApplyTime",
      render: (record, text, index) => formatDate(record)
    },
    {
      title: "借阅时间",
      key: "archivesType",
      render: (record, text) => {
        return (
          <div>
            {formatDate(record.borrowStartTime)}
            <span>——</span>
            {formatDate(record.borrowEndTime)}
          </div>
        );
      }
    },
    {
      title: "是否续借",
      key: "renew",
      dataIndex: "renew",
      render: (record, text, index) => {
        return <div>{record == 1 ? "是" : "否"}</div>;
      }
    },
    {
      title: "借阅人",
      key: "borrowUserName",
      dataIndex: "borrowUserName"
    },
    {
      title: "是否归还",
      key: "borrowState",
      dataIndex: "borrowState",
      render: (record, text) => {
        return (
          <div>
            {record == 4 ? (
              <span>已归还</span>
            ) : record == 0 || record == 2 ? (
              <span>无</span>
            ) : (
              <span>未归还</span>
            )}
          </div>
        );
      }
    },
    // {
    //   title: "借阅时间",
    //   key: "time",
    //   render: (record, text, index) => {
    //     const { borrowStartTime, borrowEndTime } = record;
    //     return (
    //       <span>
    //         {formatDate(borrowStartTime)}至{formatDate(borrowEndTime)}
    //       </span>
    //     );
    //   }
    // },
    // {
    //   title: "审核结果",
    //   key: "borrowResult",
    //   dataIndex: "borrowResult",
    //   render: (record, text, index) => {
    //     return (
    //       <Badge
    //         status={record == 1 ? "success" : "error"}
    //         text={filterBorrowState(record)}
    //       />
    //     );
    //   }
    // },
    {
      title: "操作",
      key: "operation",
      render: (record, text, index) => {
        const { borrowState } = record;
          return (
            <div>
              <a style={{ marginLeft: 10 }} onClick={() => getSliderDetails(record)}>审核详情</a>
            </div>
          );
      }
    }
  ];

  const tabProps = {
    loading:loading.effects['borrow/query'],
    dataSource: list,
    pagination,
    columns,
    onChange(page) {
      dispatch({
        type: "borrow/query",
        payload: { page: page.current, pageSize: page.pageSize }
      });
    }
  };

  return (
    <div>
      <Table {...tabProps} />
    </div>
  );
};

MyApplication.propTypes = {
  location: PropTypes.object,
  borrow: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object
};

export default connect(({ loading, borrow }) => ({ loading, borrow }))(
  MyApplication
);
